var api = require("../../utils/api");

Page({
    data: {
        posts: [],
        pageIndex: 1,
        pageCount: 20
    },
    onLoad: function (t) {
        this.getLikePosts();
    },
    onReady: function () { },
    onShow: function () { },
    onHide: function () { },
    onUnload: function () { },
    onPullDownRefresh: function () {
        this.setData({
            pageIndex: 1,
            posts: [],
            isLastPage: !1
        }),
       this.getLikePosts();
    },

    onReachBottom: function () {
        this.setData({
            isBottom: !0,
            pageIndex: this.data.pageIndex + 1
        })
        this.getLikePosts()
    },

    getLikePosts: function () {
        var that = this;
        var userId = wx.getStorageSync("userId")
        var params = {
            userId: userId,
            pageIndex: that.data.pageIndex,
            pageCount: that.data.pageCount
        }
        wx.request({
            url: api.getPicLikeList,
            method: "POST",
            data: params,
            success(res) {
                console.log(res)
                if (res.data.code == 1) {
                    var a = {};
                    res.data.data.length < that.data.pageCount && that.setData({
                        isLastPage: !0,
                        loadtext: "到底啦",
                        showloadmore: !1
                    }),
                    a.posts = [].concat(that.data.posts, res.data.data),
                    that.setData(a);
                } else {
                    wx.showToast({
                        title: res.data.message,
                    })
                }

            }
        })

        wx.stopPullDownRefresh();//关闭下拉刷新页面

    },


    bindDetail: function (t) {
        var that = this
        console.log(t);
        var e = t.currentTarget.dataset.url
        var picId1 = t.currentTarget.dataset.picid;
        var needcount = t.currentTarget.dataset.needcount;
        console.log(e);
        console.log(picId1);
        wx.navigateTo({
            url: "/pages/detail/detail?picPath=" + e + "&picId=" + picId1 + "&needcount=" + needcount
        });
    }
});